package com.hxzy.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Component
public class TokenDecode {

    /**
     * 从加密信息中获取用户信息
    * */
    public static Map<String,String> getUserInfo(String token){
        String info = token;
        Claims claims = Jwts.parser().setSigningKey("itcast").parseClaimsJws(info).getBody();//生成密钥
       //claims是一个json格式字符串{}
        Map<String,String> map = new HashMap<String, String>();

        Set<Map.Entry<String, Object>> entrys = claims.entrySet();
        for (Map.Entry<String,Object> entry: entrys) {
            map.put(entry.getKey(), entry.getKey());
        }
        return map;
    }


}
